/*
 * @Author: your name
 * @Date: 2021-08-31 19:59:24
 * @LastEditTime: 2021-08-31 20:04:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day07\10-案例排序.js
 */

var teachers = [
    { id: 3, name: "winnie", salary: 456 },
    { id: 7, name: "briup", salary: 123 },
    { id: 4, name: "jack", salary: 222 },
    { id: 9, name: "rose", salary: 777 }
];
var ascProperty = function(pro) {
    return function(t1, t2) {
        if (t1[pro] > t2[pro]) return 1;
        else return -1;
    };
}
var r1 = teachers.sort(ascProperty("id"));
console.log(r1);
var r2 = teachers.sort(ascProperty("name"));
console.log(r2);
var r3 = teachers.sort(ascProperty("salary"));
console.log(r3);